/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ucm;

import java.sql.ResultSet;
import sql.Select;

/**
 *
 * @author Donghui
 */
public class SearchBook {

    private static SearchBook local;
    private String msg;
    private String sql;
    private String[] data;
    private String[] record=new String[10];
    private ResultSet result;
    private String info;

    public static SearchBook getInstance(String tp)
    {
        if(local==null)
        {
            local=new SearchBook();
            local.msg=tp;
        }
        else
        {
            local.msg=tp;
        }
        return local;
    }

    public String run()
    {
        try{
        data=msg.split(";");
        sql="SELECT isbn,title,author,press,borrowed FROM book WHERE bid='"+data[0]+"'";
        result=Select.getInstance().selectValue(sql);
        while(result.next())
        {
            record[0]=result.getString("isbn");
            record[1]=result.getString("title");
            record[2]=result.getString("author");
            record[3]=result.getString("press");
            record[4]=result.getString("borrowed");
            info="Y;"+record[0]+";"+record[1]+";"+record[2]+";"+record[3]+";"+record[4]+";09";
        }
        }
        catch(Exception e)
        {
            info="N;09";
            e.printStackTrace();
        }
        return info;
    }

}
